package com.demo.common.base;

import com.demo.model.UserInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;

/**
 * @Description: BaseModel
 * @Author: ChenXueLi
 * @Date: 2018-10-02 11:07
 */
@Data
public class BaseModel {

    @ApiModelProperty(value = "id", name = "id")
    private int id;

    @ApiModelProperty(value = "备注", name = "remark")
    private String remark;

    @ApiModelProperty(value = "创建时间", name = "createTime")
    private Date createTime;

    @ApiModelProperty(value = "创建用户的id", name = "createUserId")
    private int createUserId;

    @ApiModelProperty(value = "创建用户的名称", name = "createUserName")
    private String createUserName;

    @ApiModelProperty(value = "修改时间", name = "modifyTime")
    private Date modifyTime;

    @ApiModelProperty(value = "修改用户的id", name = "modifyUserId")
    private int modifyUserId;

    @ApiModelProperty(value = "修改用户的名称", name = "modifyUserName")
    private String modifyUserName;

    @ApiModelProperty(value = "是否存在", name = "isDeleted")
    private int isDeleted;

    @ApiModelProperty(value = "版本号", name = "version")
    private int version;

    /**
     * 初始化信息
     * @param userInfo
     */
    public void initModel(UserInfo userInfo) {
        this.create(userInfo);
        this.modify(userInfo);
        this.isDeleted = 1;
    }

    /**
     * 初始化信息
     */
    public void initModel() {
        this.createTime = new Date();
        this.modifyTime = new Date();
        this.isDeleted = 1;
    }

    /**
     * 设置创建信息
     * @param userInfo
     */
    public void create(UserInfo userInfo) {
        this.createTime = new Date();
        this.createUserId = userInfo.getFkUserId();
        this.createUserName = userInfo.getInfoName();
    }

    /**
     * 设置修改信息
     * @param userInfo
     */
    public void modify(UserInfo userInfo){
        this.modifyTime = new Date();
        this.modifyUserId = userInfo.getFkUserId();
        this.modifyUserName = userInfo.getInfoName();
    }

}
